/**
 * 日志告警历史实体
 * 作者：GodMainCode
 * 创建时间：2024-01-17
 * 修改时间：2024-01-17
 * 修改人：GodMainCode
 */

import { 
  Entity, 
  Column, 
  PrimaryGeneratedColumn, 
  CreateDateColumn 
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { LogType, LogLevel } from '../../../interfaces/log.interface';

@Entity('log_alert_history')
export class LogAlertHistory {
  @ApiProperty({ description: '告警历史ID' })
  @PrimaryGeneratedColumn({ comment: '告警历史ID' })
  id: number;

  @ApiProperty({ description: '告警名称' })
  @Column({ length: 100, comment: '告警名称' })
  name: string;

  @ApiProperty({ description: '日志类型' })
  @Column({ 
    type: 'smallint',
    comment: '日志类型：1-操作日志 2-登录日志 3-错误日志'
  })
  type: LogType;

  @ApiProperty({ description: '日志级别' })
  @Column({ 
    type: 'enum',
    enum: LogLevel,
    comment: '日志级别'
  })
  level: LogLevel;

  @ApiProperty({ description: '触发阈值' })
  @Column({ type: 'int', comment: '触发阈值' })
  threshold: number;

  @ApiProperty({ description: '实际数量' })
  @Column({ type: 'int', comment: '实际数量' })
  actual_count: number;

  @ApiProperty({ description: '时间窗口(分钟)' })
  @Column({ type: 'int', comment: '时间窗口(分钟)' })
  time_window: number;

  @ApiProperty({ description: '通知方式' })
  @Column({ type: 'simple-array', comment: '通知方式' })
  notify_channels: string[];

  @ApiProperty({ description: '通知接收者' })
  @Column({ type: 'simple-array', nullable: true, comment: '通知接收者' })
  receivers: string[];

  @ApiProperty({ description: '通知状态：0-失败 1-成功' })
  @Column({ 
    type: 'smallint',
    default: 1,
    comment: '通知状态：0-失败 1-成功'
  })
  status: number;

  @ApiProperty({ description: '错误信息' })
  @Column({ type: 'text', nullable: true, comment: '错误信息' })
  error: string;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({ 
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间'
  })
  created_at: Date;
} 